package part15;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author wcj
 * @Date 2021/5/28 20:50
 * @Version 1.0
 */
public class Part155<T> {

    private ArrayList<T> storage = new ArrayList<>();
    private Random random = new Random(47);

    public void add(T item) {
        storage.add(item);
    }

    public T select() {
        return storage.get(random.nextInt(storage.size()));
    }

    /**
     * 随机列表，使用泛型可以创建一个存储任意类型的容器，进行复用
     *
     * @param args
     */
    public static void main(String[] args) {
        Part155<String> stringPart155 = new Part155<>();
        for (String str : "wcj love bss are you sure?".split(" ")) {
            stringPart155.add(str);
        }
        for (int i = 0; i < stringPart155.storage.size(); i++) {
            System.out.println(stringPart155.select());
        }
    }
}
